#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef struct string {
  char *ptr;
  size_t len;
} String;

void init_string(String *s) {
  s->len = 0;
  s->ptr = malloc(s->len+1);
  if (s->ptr == NULL) {
    fprintf(stderr, "malloc() failed\n");
    exit(EXIT_FAILURE);
  }
  s->ptr[0] = '\0';
}

void OutputStruct(String *s){
	printf("Address is: %x\n",s);
	printf("Value: %s\n",s->ptr);
	printf("Len: %lu\n",s->len);
}

void SetValue(String *s,char *value){
	s->ptr = value;
	s->len = strlen(value);
}

String *HiddenCopy(String *s){
	return s;
}

String DeepCopy(String *s){
	String result;
	result.ptr = s->ptr;
	result.len = s->len;
	return result;
}

int main(void)
{
	String s;
	init_string(&s);
	SetValue(&s,"234123qwe");
	
	struct string *s_hidden_copy = HiddenCopy(&s);
	struct string s_deep_copy = DeepCopy(&s);

	SetValue(s_hidden_copy,"qwe");
	OutputStruct(&s);
	printf("\n==============\nThis is s_hidden_copy: \n==============\n");
	OutputStruct(s_hidden_copy);
	printf("\n==============\nThis is s_hidden_copy: \n==============\n");
	OutputStruct(&s_deep_copy);
}
